<?php if (!defined('BASEPATH')) exit('No direct script access allowed');


/* 关于返回结果的json格式建议如下：
data:执行成功返回的数据
status:简单的表示业务执行的状态，如成功success，登录失败，更新失败等
code:业务执行状态的代码（可不设计）
message:表示详细信息
version:版本号 
*/


class User extends MY_Controller
{

    public function login(){

        


        $this->load->database();

    //     //只是取得节点本身
        $this->db->where('username', $_GET['username']);
         $this->db->where('password',$_GET['password']);      
        $query = $this->db->get('users');

   
    //     $where = " username=$username AND password =$password ";
    //     $sql = "SELECT u.*,p.title as ptitle,p.parent as ppid 
    //     FROM users u 
    //     LEFT JOIN task p ON t.grandfather=p.id 
    //     WHERE ".$where." AND t.pub=1 ORDER BY parent desc,sort desc";  
    //     $query = $this->db->query($sql);

        //  if ($query->num_rows() > 0) {
        //      $row = $query->row_array();
        //      $json_string = json_encode($row);
        //      echo $json_string;
        //  }
        //		print_r($row);
        if ($num_rows = $query->num_rows() > 0) {
            $result_array['data'] = $query->row_array();
            $result_array['status'] = 'success';
        } else {
            $result_array = array(
                'status' => 'nofound',
                'message' => '没有匹配的结果：' . $this->db->last_query()
            );
        }
        $this->array_to_json($result_array);


        //     if ($this->tank_auth->is_logged_in()) {		
        //         							// logged in
                
        //         $result = array(
        //             "code" => 20000,
        //             "data" => $row,
        //             "message" => ""
        //         );
                    
        //         $this->array_to_json($result_array);
                
        //                                     // redirect('');


        //     } elseif ($this->tank_auth->is_logged_in(FALSE)) {						// logged in, not activated
                
                
        //         redirect('/auth/send_again/');
        //     } else {

        //     }

        // $db      = \Config\Database::connect();
        // $builder = $db->table('d_user');

    //     // $query_result = $builder->get();
    //     $builder->select('id,token');
    //     $username = $this->request->getVar('username');
    //     $password = $this->request->getVar('password');
    //     $data = array(
    //         'username' => $username,
    //         'password' => $password
    //     );
    //     $builder->where($data);
    //     $query = $builder->get(1,0);
    //     $row = $query->getRow();
    //     if($row){
    //         $session = \Config\Services::session();
    //         $session->set('token', $row->token  );
    //                 // var_dump($_SESSION);
    //         $result = array(
    //             "code" => 20000,
    //             "data" => $row,
    //             "message" => ""
    //         );
    //     }else{
    //         $result = array(
    //             "code" => 20000,
    //             // "data" => $data,
    //             "message" => "验证不通过！"
    //         );
    //     }

    //     // if($page && $limit){
    //     //     $builder->limit($limit,($page-1)*10);
    //     // }
        
    //     // $request_parm = $this->request->getGetPost();
    //     // unset($request_parm['page']);//清除分页用的参数
    //     // unset($request_parm['limit']);
    //     // $request_parm = array_diff($request_parm, ["", "NULL"]);//清除值为空的参数

    //     // // print_r($builder->getCompiledSelect(false));
    //     // $query_result = $builder->get()->getResultArray();;
    //     // $count = $builder->countAllResults();


    //     return  $this->respond($result,200);





    }
}
